import React, { useState, useEffect } from 'react';
import { View } from 'react-native';
import { Toast } from '@ant-design/react-native';
import CompleteView from '../../components/CompleteView';
import { selectPlan } from '../../comconfig/sqlfun';

const Complete = ({ navigation }) => {
    const [compList, setCompList] = useState([]);
    const [searchVal, setSearchVal] = useState('');
    const getPlanList = async () => {
        try {
            const list = await selectPlan(4, searchVal);
            const arr = [];
            for (let i = 0; i < list.length; i += 1) {
                arr.push(JSON.parse(list[i]));
            }
            setCompList(arr);
        } catch (error) {
            Toast.info('获取数据失败', 1, undefined, false);
        }
    };
    useEffect(() => {
        getPlanList();
    }, [searchVal]);
    return (
        <View>
            <CompleteView
                navigation={navigation}
                compList={compList}
                getPlanList={getPlanList}
                setSearchVal={setSearchVal}
                searchVal={searchVal}
            />
        </View>
    );
};

export default Complete;
